home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: Parameterless functions
- Date: 20 Jan 1996 01:55:17 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4dpi25$vp@colossus.holonet.net>
- References: <9601191115.aa06760@paris.ics.uci.edu>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Raymond Klefstad, Ph.D. (klefstad@catalina.ICS.UCI.EDU) wrote:
-
- : Why does the following function work? Is this just gcc or is it correct
- : C++? endl and ends are implemented this way.
-
- : #include <iostream.h>
-
- : ostream& newline(ostream& out)
- : {
- : return out << "Hello";
- : }
-
- : main()
- : {
- : cout << "Hello" << newline;
- : }
-
- Really cool, isn't it? But it's not magic.
-
- A "parameterless function", i.e. a function name without the (), is
- merely a pointer to the function. In the case above, its type is
- ostream& (*)(ostream&).
-
- Look in iostream.h and you will find an appropriate << overload, e.g.
- ostream& operator<<(ostream& (*f)(ostream&)) { return (*f)(*this); }
-
- I guess it's almost magic. :)
-
- : Also, I noticed the following in some of the standard headers for gcc:
- : int foo(int x) return y
-
- It's not C++, and I wouldn't want my compiler to accept code like this.
- Are you sure this line actually compiles, or is it just a comment?
- --
- Russell Blackadar, russell@mdli.com
-